Work in Progress

The idea here is to load some BCI competition data and classify it.


In [1]:
import psychic
import numpy as np

In [2]:
from scipy.io import loadmat
m = loadmat('p300/Subject_A_Train.mat')
print m.keys()


['Signal', 'StimulusCode', '__header__', '__globals__', 'TargetChar', 'StimulusType', 'Flashing', '__version__']

In [59]:
def cl(letter):
    alphabet = [['A', 'B', 'C', 'D', 'E', 'F'],
                ['G', 'H', 'I', 'J', 'K', 'L'],
                ['M', 'N', 'O', 'P', 'Q', 'R'],
                ['S', 'T', 'U', 'V', 'W', 'X'],
                ['Y', 'Z', '1', '2', '3', '4'],
                ['5', '6', '7', '8', '9', '_']]

In [53]:
mdict = dict([(i, 'column %d' % i) for i in range(1,7)] + [(i+6, 'row %d' % i) for i in range(1,7)])
def process_trial(data, labels, target):
    d = psychic.DataSet(data.T, labels=labels.astype(int)+1, ids=np.arange(data.shape[0])/240.)
    flashes = psychic.nodes.Slice(mdict, (0, 0.7)).train_apply(d)
    return flashes

In [58]:
train = psychic.concatenate([process_trial(m['Signal'][i,:,:], m['StimulusCode'][i,:], m['TargetChar'][0][i]) for i in range(85)], ignore_index=True)

In [47]:
print process_trial(m['Signal'][0,:], m['StimulusType'][0,:])


DataSet with 61 instances, 10752 features [64x168], 2 classes: [31, 30], extras: []

In [57]:
m['TargetChar'][0]


Out[57]:
u'EAEVQTDOJG8RBRGONCEDHCTUIDBPUHMEM6OUXOCFOUKWA4VJEFRZROLHYNQDW_EKTLBWXEPOUIKZERYOOTHQI'

In [13]:
plot(m['StimulusType'][0,:])


Out[13]:
[<matplotlib.lines.Line2D at 0x7f7d4edc23d0>]

In [ ]: